<?php

$clearMap = array(
    "cache" => "../QFinance/cache/",
    "external" => "../QFinance/external/",
    "lib" => "../QFinance/lib/",
    "resources" => "../QFinance/resources/"
);

$baseMap = array(
    "external" => array(
        // Fugue Icons 3.0
        array("from" => "../external/resources/Fugue-icons-3.0-src/icons/", "to" => "../QFinance/external/resources/Fugue-icons-3.0-src/"),
        // Ext JS 3.3.1 
        array("from" => "../external/lib/Ext-3.3.1/ext-all-debug-w-comments.js", "to" => "../QFinance/external/lib/Ext-3.3.1/js/ext-all-debug-w-comments.js"),
        array("from" => "../external/lib/Ext-3.3.1/ext-all.js", "to" => "../QFinance/external/lib/Ext-3.3.1/js/ext-all.js"),
        array("from" => "../external/lib/Ext-3.3.1/src/locale/ext-lang-pt_BR.js", "to" => "../QFinance/external/lib/Ext-3.3.1/js/ext-lang-pt_BR.js"),
        array("from" => "../external/lib/Ext-3.3.1/resources/css/ext-all.css", "to" => "../QFinance/external/lib/Ext-3.3.1/css/ext-all.css"),
        array("from" => "../external/lib/Ext-3.3.1/resources/images/default/", "to" => "../QFinance/external/lib/Ext-3.3.1/images/default/"),
        // Ext Base 
        array("from" => "../external/lib/Ext-3.3.1/adapter/ext/ext-base-debug.js", "to" => "../QFinance/external/lib/Ext-3.3.1/js/ext-base-debug.js"),
        array("from" => "../external/lib/Ext-3.3.1/adapter/ext/ext-base.js", "to" => "../QFinance/external/lib/Ext-3.3.1/js/ext-base.js"),
        // Ext UX     
        array("from" => "../external/lib/Ext-3.3.1/examples/ux/css/ux-all.css", "to" => "../QFinance/external/lib/Ext-3.3.1/css/ux-all.css"),
        array("from" => "../external/lib/Ext-3.3.1/examples/ux/ux-all-debug.js", "to" => "../QFinance/external/lib/Ext-3.3.1/js/ux-all-debug.js"),
        array("from" => "../external/lib/Ext-3.3.1/examples/ux/ux-all.js", "to" => "../QFinance/external/lib/Ext-3.3.1/js/ux-all.js"),
        array("from" => "../external/lib/Ext-3.3.1/examples/ux/images/", "to" => "../QFinance/external/lib/Ext-3.3.1/images/"),
        array("from" => "../external/lib/Ext-3.3.1/examples/ux/statusbar/images/", "to" => "../QFinance/external/lib/Ext-3.3.1/images/"),
        // Highcharts 2.1.4
        array("from" => "../external/lib/Highcharts-2.1.4/js/highcharts.src.js", "to" => "../QFinance/external/lib/Highcharts-2.1.4/js/highcharts.src.js"),
        array("from" => "../external/lib/Highcharts-2.1.4/js/highcharts.js", "to" => "../QFinance/external/lib/Highcharts-2.1.4/js/highcharts.js"),
        // Sencha Touch
        array("from" => "../external/lib/Sencha-touch-1.0.1a/sencha-touch-debug-w-comments.js", "to" => "../QFinance/external/lib/Sencha-touch-1.0.1a/js/sencha-touch-debug-w-comments.js"),
        array("from" => "../external/lib/Sencha-touch-1.0.1a/sencha-touch.js", "to" => "../QFinance/external/lib/Sencha-touch-1.0.1a/js/sencha-touch.js"),
        array("from" => "../external/lib/Sencha-touch-1.0.1a/sencha-touch.js", "to" => "../QFinance/external/lib/Sencha-touch-1.0.1a/js/sencha-touch.js"),
        array("from" => "../external/lib/Sencha-touch-1.0.1a/resources/css/sencha-touch.css", "to" => "../QFinance/external/lib/Sencha-touch-1.0.1a/css/sencha-touch.css"),
    ),
    "lib" => array(
        array("from" => "../lib/", "to" => "../QFinance/lib/")),
    "resources" => array(
        array("from" => "../resources/", "to" => "../QFinance/resources/"))
);

//$developmentMap =
//$productionMap =

function buildDevelopment() {
    clearDevelopment();
    copyDevelopment();
}

function clearDevelopment() {
    $clearMap = $GLOBALS["clearMap"];
    foreach ($clearMap as $itemName => $directoryToClear) {
        echo "Cleaning item '" . $itemName . "' directory '" . $directoryToClear . "'" . PHP_EOL;
        rrmdir($directoryToClear);
    }
}

function copyDevelopment() {
    $baseMap = $GLOBALS["baseMap"];
    foreach ($baseMap as $itemName => $copyTasks) {
        echo "Item '" . $itemName . "'" . PHP_EOL;
        foreach ($copyTasks as $copyTask) {
            echo "Copying '" . $copyTask["from"] . "' to '" . $copyTask["to"] . "'" . PHP_EOL;
            rcopy($copyTask["from"], $copyTask["to"]);
            if (!file_exists(pathinfo($copyTask["to"], PATHINFO_DIRNAME))) {
                touch(pathinfo($copyTask["to"], PATHINFO_DIRNAME) . "/DO NOT MODIFY OR DO VERSION OF THIS DIRECTORY - GENERATED BY BUILD");
            }
        }
    }
}

?>